<template>
    <div class="ccui-multifunctional-table-wrapper">
        <el-table
            :data="showTableData"
            max-height="525"
            ref="tableList"
            border
            :summary-method="getSummaries"
            show-summary
        >
            <el-table-column
                v-for="(item, i) in tableColumnList"
                :label="item.label"
                :fixed="item.fixed"
                :type="item.type"
                :prop="item.prop"
                :header-align="item.headerAlign || 'left'"
                :align="item.align"
                :min-width="item.width"
                :key="i"
                :show-overflow-tooltip="true"
            >
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import BigNumber from "bignumber.js";

export default {
    name: "tableList",
    data() {
        return {
            showTableData: [],
            tableColumnList: [
                {
                    type: "index",
                    label: "序号",
                    fixed: "left",
                    width: "55"
                },
                {
                    label: "设备物资编码",
                    prop: "materialCode",
                    width: "110"
                },
                {
                    label: "验收单编号",
                    prop: "acceptCode",
                    width: "130"
                },
                {
                    label: "设备物资名称",
                    prop: "materialName",
                    width: "300"
                },
                {
                    label: "设备物资说明",
                    prop: "materialState",
                    width: "130"
                },
                {
                    label: "单位",
                    prop: "measureUnit",
                    width: "100"
                },
                {
                    label: "验收日期",
                    prop: "acceptTime",
                    width: "100"
                },
                {
                    label: "剩余可结算数量",
                    prop: "unTransportCount",
                    width: "130"
                },
                {
                    label: "冲销数量",
                    prop: "settlementCount",
                    width: "100"
                },
                // {
                //     label: "税率",
                //     prop: "taxRatePercent"
                // },
        
                {
                    label: "含税单价",
                    prop: "unitPriceWithTax",
                    width: "130"
                },
                {
                    label: "冲销金额",
                    prop: "moneyWithTax",
                    width: "130"
                },
                // {
                //     label: "不含税单价",
                //     prop: "unitPriceWithoutTax",
                //     width: "150",
                //     align: "right"
                // },
                // {
                //     label: "不含税金额",
                //     prop: "moneyWithoutTax",
                //     width: "150",
                //     align: "right"
                // },
                {
                    label: "生产厂家/品牌",
                    prop: "brand",
                    width: "130"
                }
            ]
        }
    },
    methods: {
        getSummaries(param) {
            const {columns, data} = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = "合计";
                    return;
                }
                const values = data.map(item => Number(item[column.property]));
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr, rowIndex) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            if (column.label == "结算数量") {
                                if (data[rowIndex].isMerge == 1 && data[rowIndex].isMainInventory == 0) {
                                    return prev;
                                }
                                return new BigNumber(+prev).plus(+curr).toString();
                            } else if (column.label == "含税金额" || column.label == "不含税金额") {
                                if (data[rowIndex].isMerge == 1 && data[rowIndex].isMainInventory == 0) {
                                    return prev;
                                }
                                return new BigNumber(+prev).plus(+curr).toString();
                            }
                        } else {
                            return (prev = " ");
                        }
                    }, 0);
                    if (column.label == "结算数量") {
                        sums[index] = (+sums[index]).toFixed(3);
                    }
                    if (column.label == "含税金额") {
                        sums[index] = (+sums[index]).toFixed(2);
                    }
                } else {
                    sums[index] = "";
                }
            });
            return sums;
        },
    }
}
</script>

<style scoped>

</style>